package com.myorg.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.sun.jersey.core.util.Base64;

public class HashFunctionHelper {
	public static String getHash(String emailID, byte[] salt) throws NoSuchAlgorithmException,
			UnsupportedEncodingException {
		MessageDigest digest = MessageDigest.getInstance("SHA-256");
		digest.reset();
		digest.update(salt);
		return new String(Base64.encode(digest.digest(emailID.getBytes("UTF-8"))), "UTF-8");
	}

	public static byte[] getSalt() {
		try {
			return "=had00p=".getBytes("UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}
